package com.app.util;

import org.apache.log4j.Logger;

import java.util.Properties;

/**
 * Created by IntelliJ IDEA.
 * User: dourmur
 * Date: 12/7/11
 * Time: 10:20 AM
 * To change this template use File | Settings | File Templates.
 */
public class PropertiesHelper {

    private static final String NOT_FOUND = "Propertie not found";
    private static final Logger logger = Logger.getLogger(PropertiesHelper.class);
    /**
     * This method return the content of environment.properties file.
     * @param key
     * @return {@link String}
     */
    public static String getEnvironment(String key){
        String result = "";
        try{
            logger.info("Getting environment configuration");
            result = getConfiguration("environment.properties", key);
        } catch (Exception ex){
            logger.error(ex);
        }
        return result;
    }
    /**
     * This method return a configuration at properties file.
     * @param file
     * @param key
     * @return {@link String}
     */
    private static String getConfiguration(String file, String key){
        String result = "";
        Properties p = new Properties();
        try{
            p.load(PropertiesHelper.class.getClassLoader().getResourceAsStream(file));
            result = (p.getProperty(key) == null)? NOT_FOUND : p.getProperty(key);
        }catch(Exception ex){
            logger.error(ex);
        }
        return result;
    }
}